package org.redmaple.core.pkstrategy;

import org.apache.commons.lang.StringUtils;

/**
 * 字符串类型的主键生成策略
 * 
 * @author Xiangyun
 *
 */
public class StringGeneratedStrategy extends AbstarctStringGeneratedStrategy {

	/**
	 * 主键值，默认为空字符串
	 */
	private String value = StringUtils.EMPTY;

	/**
	 * 自定义的前缀
	 */
	private AbstarctStringGeneratedStrategy prefix;

	/**
	 * 自定义的后缀
	 */
	private AbstarctStringGeneratedStrategy suffix;

	public StringGeneratedStrategy(String value,
			AbstarctStringGeneratedStrategy prefix,
			AbstarctStringGeneratedStrategy suffix) {
		this.value = value;
		this.prefix = prefix;
		this.suffix = suffix;
	}

	public StringGeneratedStrategy(AbstarctStringGeneratedStrategy prefix,
			AbstarctStringGeneratedStrategy suffix) {
		this.prefix = prefix;
		this.suffix = suffix;
	}

	public StringGeneratedStrategy(String value) {
		this.value = value;
		this.prefix = new StringGeneratedStrategy();
		this.suffix = new StringGeneratedStrategy();
	}
	
	public StringGeneratedStrategy() {
		this.prefix = new StringGeneratedStrategy();
		this.suffix = new StringGeneratedStrategy();
	}

	public String getValue() {
		StringBuilder buffer = new StringBuilder();
		if (null != prefix) {
			buffer.append(prefix.getValue());
		}
		buffer.append(value);
		if (null != suffix) {
			buffer.append(suffix.getValue());
		}
		return buffer.toString();
	}

}
